﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YuShiManageSystem.DATA
{
    public class StoreService
    {
        private YuShiManageSystem.DATA.DataModel DataModel;
        public StoreService(YuShiManageSystem.DATA.DataModel datamodel)
        {
            this.DataModel = datamodel;
        }

        /// <summary>
        /// 返回可用的门店列表
        /// </summary>
        /// <returns></returns>
        public string[] GetStoreNameArray()
        {
            return this.DataModel.tb_store.Select(t => t.sName).ToArray();
        }

        public tb_store Login(string storeName, string passWord, out string errorText)
        {
            
            if (String.IsNullOrEmpty(storeName) || string.IsNullOrEmpty(passWord))
            {
                errorText = "用户名或密码不能为空";
                return null;
            }

            tb_store stroe = this.DataModel.tb_store.Where(t => t.sName.Equals(storeName) && t.password.Equals(passWord)).FirstOrDefault();
            if (stroe == null)
            {
                errorText = "密码不正确!";
                return null;
            }
            errorText = "";
            return stroe;
            
        }
    }
}
